home *** CD-ROM | disk | FTP | other *** search
- ******************************************************************
- * COPYRIGHT (C) 1986 by Donald Krantz and James Stanley
- * - Note: This is a real, live, actual, registered copyright,
- * and should be treated as such. This source code is from
- * the book "68000 Assembly Language", Krantz and Stanley,
- * Addison-Wesley Publishing Company, Reading, MA, 1986.
- *
- * Permission granted by the authors for non-commercial use
- * in programs released to the public domain, as long as this
- * copyright notice remains attached and visible.
- *
- *****************************************************************
- * GROUP 1 (Quick) Commands
-
- xref _getkey,ask,case,cnt_nl,default,dirty,eol,findpat
- xref prompt,repflag,reppat,seek,sol
- xdef group_1,refind,to_end,home
-
- #edit.h
- #cursor.h
- *****************************************************************
- * GROUP_1 - group 1 (quick) commands
- group_1:
- move.l #q_cmd,a0 * load up prompt address
- bsr prompt * output prompt
- bsr _getkey * get switch key
- and.w #$001F,d0 * make u/l, l/c letters cntrl
- move.l #table1,a0 * load up case table address
- bra case * returns to caller of group_2
- q_cmd: dc.b 'Quick Command: A B C D F K R S',0
- dc.w 0
-
- *****************************************************************
- * TABLE_1 - switch table for group 1 commands
- table1:
- dc.w 8
- dc.w $01 * ^A find/replace
- dc.l find_repl
- dc.w $02 * ^B find block start
- dc.l find_b_s
- dc.w $03 * ^C to end of file
- dc.l to_end
- dc.w $06 * ^F find
- dc.l find
- dc.w $0B * ^K find block end
- dc.l find_b_e
- dc.w $04 * ^D end of line
- dc.l eol
- dc.w $12 * ^R top of file
- dc.l home
- dc.w $13 * ^S start of line
- dc.l sol
- dc.l default
- *****************************************************************
- find:
- move.l #fwhat,a0 * prompt string address
- move.l #findpat,a1 * find pattern string address
- bsr ask * see what human wants
- clr.w repflag * zero "replace" flag
- bsr refind * go find it
- rts
- fwhat: dc.b 'Find: ',0
- dc.w 0
- *****************************************************************
- find_repl:
- move.l #fwhat,a0 * prompt string address
- move.l #findpat,a1 * find pattern string address
- bsr ask * see what human wants
- move.l #rwhat,a0 * prompt string address
- move.l #reppat,a1 * replace pattern string address
- bsr ask * get reply
- move.w #-1,repflag * set "replace" flag
- bsr refind * go find it
- rts
- rwhat: dc.b 'Replace: ',0
- dc.w 0
- *****************************************************************
- refind:
- move.l e_buf(a5),d0 * calculate bytes past cursor
- sub.l e_gap(a5),d0 * D0 is bytes + 1
- addq.l #1,d0 * adjust byte count to actual
- move.l e_gap(a5),a0 * a0 will be search location
- andi #$FB,ccr * reset zero flag
- bra sk0_ref * do loop test before looping
- lp0_ref:
- move.l #findpat,a1 * a1 will be search pattern
- addq.l #1,a0 * bump start pointer
- bsr instr * do instring compare
- sk0_ref:
- dbeq d0,lp0_ref * loop if (d0) AND not zero flag
- bne sk1_ref * jump if not found
- move.l e_gap(a5),a2 * setup to move cursor
- move.l b_gap(a5),d0 * calculate bytes to move
- sub.l a2,a0 * a0 holds bytes to move
- add.l a0,d0 * a1 is desired cursor location
- bsr seek * move cursor
- tst.w repflag * see if we're replacing
- beq sk2_ref * jump if no.
- * replace
- bsr dirty * mark file as modified
- move.l #findpat,a1 * we'll use brute force
- move.l e_gap(a5),a0 * get end-of-gap
- lp1_ref:
- tst.b (a1)+ * look for end-of-find-pattern
- beq sk3_ref * jump out at end of pattern
- addq.l #1,a0 * pop character out of file
- bra lp1_ref * keep it up
- sk3_ref:
- move.l a0,e_gap(a5) * delete "found" pattern
- * insert replacement string
- * we really ought to check for room here...
- move.l #reppat,a1 * replacement string address
- move.l b_gap(a5),a0 * destination for string
- move.l a0,d0 * save cursor position for later
- lp2_ref:
- tst.b (a1) * see if we have stuff to insert
- beq sk4_ref * nope, all done.
- move.b (a1)+,(a0)+ * transfer a byte
- bra lp2_ref * try for next byte
- sk4_ref:
- move.l a0,b_gap(a5) * reset gap position
- bsr seek * fix cursor position
- bra sk2_ref * finished.
- sk1_ref:
- move.w #12,ed_err(a5) * string-not-found error
- sk2_ref:
- bsr cnt_nl * adjust line counter
- rts
- *****************************************************************
- * INSTR - tests if a string in contained in the buffer.
- instr:
- clr.l d1 * d1 is compare count
- lp0_str:
- tst.b (a1) * at end of pattern string?
- beq sk0_str * jump if yes (we found it)
- addq.l #1,d1 * increment compare count
- cmp.b (a1)+,(a0)+ * check a byte - equal?
- beq lp0_str * jump if no - no match
- sk0_str:
- sub.l d1,a0 * reset compare pointer
- sub.l d1,a1 * reset source pointer
- rts
- *****************************************************************
- * HOME - moves cursor to top of file
- home:
- move.l b_gap(a5),d0 * get number of bytes to xfer
- sub.l b_buf(a5),d0 * d0 is number of bytes
- move.l b_gap(a5),a0 * a0 is source address
- move.l e_gap(a5),a1 * a1 is destination address
- bra sk0_hm * loop test before 1st transfer
- lp0_hm:
- move.b -(a0),-(a1) * transfer across cursor gap
- sk0_hm:
- dbra d0,lp0_hm * loop for all chars
- move.l a0,b_gap(a5) * save ending positions
- move.l a1,e_gap(a5)
- clr.w log_lin(a5) * reset current line counter
- rts
- *****************************************************************
- * FIND_B_S - move the cursor to the beginning of the block
- find_b_s:
- move.l blk_st(a5),d0 * load marker
- beq sk0_fbs * if zero, there's an error
- bsr seek * go find the spot
- bsr cnt_nl * reset line count
- rts
- sk0_fbs:
- move.w #4,ed_err(a5) * mark edit error #4 (block mark)
- rts
- *****************************************************************
- * FIND_B_E - move the cursor to the end of the block
- find_b_e:
- move.l blk_end(a5),d0 * load marker
- beq sk0_fbe * if zero, block's not marked.
- bsr seek * go to the spot
- bsr cnt_nl * reset line count
- rts
- sk0_fbe:
- move.w #4,ed_err(a5) * mark edit error #4 (block mark)
- rts
- *****************************************************************
- * TO_END - moves cursor to end of file
- to_end:
- move.l e_buf(a5),d0 * get number of bytes to xfer
- sub.l e_gap(a5),d0 * d0 is number of bytes + 1
- move.l e_gap(a5),a0 * a0 is source address
- move.l b_gap(a5),a1 * a1 is destination address
- addq.l #1,d0 * adjust index for cursor update
- bra sk0_te * loop test before 1st transfer
- lp0_te:
- move.b (a0)+,(a1)+ * transfer across cursor gap
- sk0_te:
- dbra d0,lp0_te * loop for all chars
- move.l a0,e_gap(a5) * save ending positions
- move.l a1,b_gap(a5)
- bsr cnt_nl * count lines to cursor
- rts